package pwd.allen.util.jackson;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.Data;
import pwd.allen.entity.Order;

import java.util.Date;
import java.util.List;

/**
 * jackson xml转换
 * 需要引入 jackson-dataformat-xml
 *
 * @author 门那粒沙
 * @create 2020-10-31 20:46
 **/
@Data
@JacksonXmlRootElement(localName = "myXml")
public class MyJacksonXml {
    private String str;
    private Integer i;
    private Float f;
//    @JsonFormat(pattern = "yyyy-MM-dd")  // TODO 转字符串正常，但是字符串转实体类报错：com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String
    private Date date;
    @JacksonXmlElementWrapper(localName="orders")
    @JacksonXmlProperty(localName="order")
    private List<Order> orders;
}
